const express = require('express');
const static = require('express-static');
const bodyParser = require('body-parser');
const multer = require('multer');
const multerObj = multer({dest: './static/upload'});
const mysql = require('mysql');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');
const consolidate = require('consolidate');
const expressRoute = require('express-route');

var server = express();
server.listen(8080);

//1.获取到请求数据
//get 自带
server.use(bodyParser.urlencoded());
server.use(multerObj.any());


//2.cookie session
server.use(cookieParser());
(function(){
    var keys = [];
    for(var i=0;i<100;i++){
        keys[i] = 'a_'+Math.random();
    }
    server.use(cookieSession({
        name: 'sess_id',
        keys: keys,
        maxAge: 20*60*1000
    }));
})();

//3.模版
server.engine('html',consolidate.ejs);
server.set('views','template');
server.set('view engine', 'html');

//4.route
// var createRouter = require('./route/1.js');
// server.use('/article/',createRouter());

//server.use('/article/',require('./route/1.js')());
//server.use('/blog/',require('./route/2.js')());

// server.use('/',require('./route/web.js')());
// server.use('/admin/',require('./route/admin/index.js')());


server.use('/web/',require('./route/web')());
server.use('/admin/',require('./route/admin')());


//5.default ： static
server.use(static('./static/'));